package com.zy.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zy.mapper.PurchaseMapper;
import com.zy.pojo.Purchase;
import com.zy.pojo.Staff;
import com.zy.service.PurchaseService;
import com.zy.vo.ManagementVo;
import com.zy.vo.Purchase.PurchaseVo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;
@Service("PurchaseService")
public class PurchaseServiceImpl extends ServiceImpl<PurchaseMapper, Purchase> implements PurchaseService {
    @Resource
    private PurchaseMapper purchaseMapper;
    @Override
    public PurchaseVo getPurList(Integer pageNo, Integer pageSize,ManagementVo managementVo) {
        Page page =new Page();
        page.setSize(pageSize);
        page.setCurrent(pageNo);
        QueryWrapper queryWrapper =new QueryWrapper();
        queryWrapper.like(!StringUtils.isEmpty(managementVo.getUserCode()),"cg_contract",managementVo.getUserCode())
                .gt(managementVo.getQtime()!=null,"cg_cgdata",managementVo.getQtime())
                .lt(managementVo.getZtime()!=null,"cg_cgdata",managementVo.getZtime());
        List<Purchase> list =purchaseMapper.getPurList(page,queryWrapper);
        return new PurchaseVo(list,page.getTotal());
    }

    @Override
    public void add(Purchase purchase) {
        purchaseMapper.insert(purchase);
    }

    @Override
    public void update(Purchase purchase) {
        purchaseMapper.updateById(purchase);
    }

    @Override
    public void del(Integer id) {
        purchaseMapper.deleteById(id);
    }

    @Override
    public void select(Integer id) {
        purchaseMapper.selectById(id);
    }

    @Override
    public void Oupdate(Purchase purchase) {
        purchaseMapper.update(purchase);
    }

    @Override
    public void getPurchasemxadd(Integer cgLingcode,String goodsName,Integer Lingroot,Integer djia, Integer dshu,Integer zmoney) {
        purchaseMapper.getPurchasemxadd(cgLingcode,goodsName,Lingroot, djia, dshu,zmoney);
    }

    @Override
    public void getDelpur(Purchase purchase) {
        purchaseMapper.getPurdeladd(purchase);
    }

}
